import ApplicationContext  from  './ApplicationContext.js';

import  JsrLoad from './load/JsrLoad.js'


import  RunLoad  from  './load/RunLoad.js';
import  AopContext  from './aopDecorator/AopContext.js';
import  Aop  from './aopDecorator/Aop.js';
import Service    from  './decorator/Service.js';
import Resource    from  './decorator/Resource.js';
import AopFactory    from  './AopFactory.js';
import Modular from './reactDecorator/Modular.js'

const inBrowser = typeof window !== 'undefined'

class QGuanRunApplication{

    constructor(parmList,resolve){
      // this.applicationContext =ApplicationContext.getInstance();
        console.log("启动 轻管")
      let context=  this.applicationContext=ApplicationContext.getInstance();
        if(inBrowser){
            window.qguan=context
        }else {
            global.qguan =context
        }
        qguan.inBrowser=inBrowser;


        let aopContext=new AopContext();
         context.saveBend('aopContext',aopContext) ;// aop
        let jsrLoad=new JsrLoad();
        context.saveBend('jsrLoad',jsrLoad) ;//
        let aopFactory=new AopFactory();
        context.saveBend("aopFactory",aopFactory)
        context.saveBend("service",Service);
        context.saveBend("resource",Resource);
        context.saveBend("aop",Aop);

        context.saveBend("modular",Modular);
        if(inBrowser){
            window.qguan=context
        }else {
            global.qguan =context
        }
        qguan.inBrowser=inBrowser;
     return  RunLoad(parmList,resolve);

    }

}

export default function runApplication(...list) {

    return function (target) {
     let res=  new Promise(function(resolve ){
           return new QGuanRunApplication(list,resolve)
        }).then(function () {
            console.log("启动成功")
        }) ;
    }

}
